# 字符串的编码和解码
a = "德里克".encode('utf-8')
print(a)
b = a.decode('utf-8')
print(b)

# 字符串的CRUD
# Creat
a = "Derek"
b = a + ' hello!'
print(b)
# Retrieve---检索
a = ['Derek', [1, 2], (2, 3, 4)]
d = a[0]
b = a[1]
c = a[2]
print("{}, {}, {}".format(b, c, d))
a = "Derek, Hello"
b = a.find('!')
c = a.find('e')
print("{},{}".format(b,c))
b = a.index('e')
print(b)
# update
a = "Dorok,hello"
b = a.replace('o', 'e')
print(b)

a = "Derek, Mary, Ivan"
b = a.split(',')
print(b)
c = '#'.join(b)
print(c)

# Delete
a = "        hello, Derek        "
b = a.strip()
print(b)
b = a.lstrip()
print(b)
b = a.rstrip()
print(b)

# 字符串输入输出
# 保存文件
file_1 = open('Derek.txt', 'w', encoding="utf-8")
content = 'Derek, hello'
file_1.write(content)
file_1.close()
# 读取文件
file_2 = open('Derek.txt', 'r', encoding='utf-8')
content = file_2.read()
print(content)
file_2.close()
# 追加文件
file_3 = open('Derek.txt', 'a', encoding="utf-8")
content = "\nyou are so handsome that I love you"
file_3.write(content)
file_3.close()

# 字符串输入输出
a = "so"
b = "handsome"
print(f"Derek, you are : {a}, {b}")

# 小数格式化
b = "{:.2f}".format(3.1415926)
print(b)
